﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

using MaxStudio.Concrete.DBUtility;

namespace MaxStudio.Concrete.Server.Dao
{
    public partial class ConcreteDaoDataContext : System.Data.Linq.DataContext
    {
        #region ReceivableDao

        public List<tb_Receivable> GetAllReceivable()
        {

            var query = (from obj in this.tb_Receivables
                         where obj.IsDelete == 0
                         select obj).ToList();
            return query;
        }

        public tb_Receivable GetReceivableById(int id)
        {
            return this.tb_Receivables.SingleOrDefault(tb_Receivables => tb_Receivables.Id == id);
        }

        public void CreateReceivable(tb_Receivable entity)
        {
            entity.CreateDate = DateTime.Now;
            entity.CreateBy = 1;
            entity.ModifyDate = DateTime.Now;
            entity.ModifyBy = 1;
            tb_Receivables.InsertOnSubmit(entity);
            this.SubmitChanges();

        }

        public void ModifyReceivable(tb_Receivable entity)
        {
            tb_Receivable instance = this.tb_Receivables.SingleOrDefault(p => p.Id == entity.Id);
            instance.Amount = entity.Amount;
            instance.ContranctId = entity.ContranctId;
            instance.Description = entity.Description;
            instance.HaveBill = entity.HaveBill;
            instance.Id = entity.Id;
            instance.IsDelete = entity.IsDelete;
            instance.Round = entity.Round;
            instance.Status = entity.Status;
            instance.Traker = entity.Traker;
           
            instance.IsDelete = entity.IsDelete;
            instance.ModifyBy = 1; //Need to get current user
            instance.ModifyDate = DateTime.Now;

            this.SubmitChanges();
        }
        public void DeleteReceivable(tb_Receivable entity)
        {
            tb_Receivable deleteEntity = tb_Receivables.SingleOrDefault(p => p.Id == entity.Id);
            tb_Receivables.DeleteOnSubmit(deleteEntity);

            this.SubmitChanges();
        }

        #endregion

    }
}
